package org.cnbi.utils.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.cnbi.entity.IndicatorExpression;
import org.cnbi.utils.pojo.dash.ItemBean;
import org.cnbi.utils.pojo.dash.ModelBean;
import org.cnbi.utils.pojo.indicator.IndicatorDimBean;
import org.cnbi.utils.pojo.indicator.IndicatorParams;

public class OjbectConvertUtil {
	
	private static final Log logger = LogFactory.getLog(OjbectConvertUtil.class);
	/**
	 * SET转换MAP
	 * @param str
	 * @return
	 */
	public static Map<Object, Object> SetToMap(Set<Object> setobj) {
		Map<Object, Object> map = getHashMap();
		for (Object obj: setobj) {
			  System.out.println(obj.toString());
		}
		for (Iterator iterator = setobj.iterator(); iterator.hasNext();) {
			Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) iterator.next();
			map.put(entry.getKey().toString(), entry.getValue() == null ? "" : entry.getValue().toString().trim());
		}
		/*for (Map.Entry<Object, Object> entry:map.entrySet()) {
			Object key = entry.getKey();
			Object value = entry.getValue();
			map.put(entry.getKey().toString(), entry.getValue() == null ? "" : entry.getValue().toString().trim());
		}*/
		return map;

	}
	
	/**
	 * 获取Map对象
	 */
	public static Map<Object, Object> getHashMap() {
		return new HashMap<Object, Object>();
	}
	
	public static ItemBean getItemBean(Object object,ModelBean db){
		if(object instanceof ItemBean){//item,fact,company,period
			return (ItemBean)object;
		}else{
			logger.info("有关模型====【"+db.getTitle()+"---id=="+db.getId()+"】的文件初始不正确！");
		}
		return null;
	}
	

	/**
	 * 指标，公司，期间组合成 list
	 * @param map
	 * @return
	 */
	public static List<IndicatorDimBean> getIndicatorDimBeanList(Map<Integer,IndicatorExpression> map,IndicatorParams params){
		List<IndicatorDimBean> list = new ArrayList<IndicatorDimBean>();
				for (int i : params.getIndicator()) {
					for (String c:params.getCompany()){
						for (String p:params.getPeriod()){
							  list.add(new IndicatorDimBean(i,c,p,(IndicatorExpression)map.get(i).clone()));
						}
					}
				}
		return list;
	}

}
